package com.ccloud.common.core.constant;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

/**
 * @author chentailai
 * @version V1.0
 * @Project ccloud-parent
 * @Title BizConstant.java
 * @Description 业务通用常量池
 * @Package com.hd.common.constant
 * @date 2020/12/24 11:30 上午
 */
public class BizConstant {

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum Common {
        YEAR("y", "年"),
        MONTH("m", "月"),
        WEEK("w", "周"),
        DAY("d", "日"),
        FIELD("field", "属性"),
        COLON(":", "冒号 "),
        UNDERLINE("_", "下划线"),
        VAL("val", "值"),
        DURATION_INIT_VAL("0", "连续驾驶时长初始值"),
        STR_ONE("1", "字符串1"),
        POINT(".", "小数点"),
        SEPARATOR(",", "分隔符"),
        BLACK("", "空白"),
        INVALID_DATE("Invalid date", "不合法的日期"),
        BASE64("base64", "图片格式base64"),
        ADMINISTRATOR(null, "admin"),
        DATE_FORMAT_INTERNET("yyyy-MM-dd'T'HH:mm:ss", "国际时间格式"),
        DATE_FORMAT_DAY_NO_SEPARATOR("yyyyMMdd", "年月日格式无需分隔符"),
        DATE_FORMAT_DAY("yyyy-MM-dd", "年月日格式"),
        DATE_FORMAT_MONTH("yyyy-MM", "年月格式"),
        DATE_FORMAT_YEAR("yyyy", "年格式"),
        DATE_FORMAT_HMS("HH:mm:ss", "时分秒格式"),
        DATE_FORMAT_SECOND("yyyy-MM-dd HH:mm:ss", "年月日 时分秒格式");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            Common[] list = Common.values();
            for (Common one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum Columns {
        MONTH("month", "月"),
        URL("url", "文件地址"),
        FILE_NAME("file_name", "文件名称"),
        DAY("day", "日");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            Columns[] list = Columns.values();
            for (Columns one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum OpsType {
        INSERT("insert", "插入"),
        UPDATE("update", "更新");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            OpsType[] list = OpsType.values();
            for (OpsType one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }


    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum HandleStatus {
        UN_HANDLED("0", "未处理"),
        HANDLED("1", "已处理");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            HandleStatus[] list = HandleStatus.values();
            for (HandleStatus one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum VerifyStatus {
        UN_VERIFIED("0", "未审核"),
        VERIFIED("1", "已审核");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            VerifyStatus[] list = VerifyStatus.values();
            for (VerifyStatus one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum GenerateStatus {
        GENERATING("0", "生成中..."),
        RE_GENERATING("2", "重新生成中..."),
        GENERATED("1", "已生成");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            GenerateStatus[] list = GenerateStatus.values();
            for (GenerateStatus one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum RealData {
        REALTIME("1", "实时"),
        SUPPLEMENT("0", "补报");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            RealData[] list = RealData.values();
            for (RealData one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }


    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum AlarmRecordType {
        HANDLE_RECORD("0", "处理台账"),
        VERIFY_RECORD("1", "审核台账");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            AlarmRecordType[] list = AlarmRecordType.values();
            for (AlarmRecordType one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum RuleTransType {
        PASSENGER("1", "客运"),
        DANGER("2", "危险品运输"),
        FREIGHT("3", "货运"),
        ALL("all", "全部");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static RuleTransType get(String key) {
            if (StringUtils.isBlank(key)) return null;
            RuleTransType[] list = RuleTransType.values();
            for (RuleTransType one : list) {
                if (one.key.equals(key)) {
                    return one;
                }
            }
            return null;
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum AlarmType {
        OVER_SPEED("0", "超速", "over_speed"),
        FATIGUE_DRIVE("1", "疲劳驾驶", "fatigue_drive"),
        NIGHT_NO_ENTRY("2", "夜间禁行", "night_no_entry"),
        OFF_GPS("3", "不定位", "off_gps"),
        OFF_LINE("4", "无数据", "off_line");

        private String key;
        private String val;
        private String property;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static AlarmType get(String key) {
            if (StringUtils.isBlank(key)) return null;

            AlarmType[] list = AlarmType.values();
            for (AlarmType one : list) {
                if (one.key.equals(key)) {
                    return one;
                }
            }
            return null;
        }

        /**
         * @return com.hd.common.constant.BizConstant.AlarmType
         * @author chentailai
         * @description 根据key模糊匹配
         * @date 2021/2/20 8:52 上午
         * @params [key]
         */
        public static AlarmType getLike(String key) {
            if (key.contains("over_speed")) return AlarmType.OVER_SPEED;
            if (key.contains("fatigue")) return AlarmType.FATIGUE_DRIVE;
            if (key.contains("night")) return AlarmType.NIGHT_NO_ENTRY;
            if (key.contains("gps")) return AlarmType.OFF_GPS;
            if (key.contains("line")) return AlarmType.OFF_LINE;

            return AlarmType.OFF_GPS;
        }

    }


    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum VehicleTransType {
        PASSENGER("1", "班线客运", "passenger", "班车"),
        TRAVEL("2", "旅游客运", "travel", "包车"),
        FREIGHT("3", "普通货物运输", "freight", "普通货物"),
        DANGER("4", "危险品运输", "danger", "危险"),
        OTHER("5", "其他", "other", "其他");


        private String key;
        private String val;
        private String property;
        private String transTypeKey;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            VehicleTransType[] list = VehicleTransType.values();
            for (VehicleTransType one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

        /**
         * @return com.hd.common.constant.BizConstant.VehicleTransType
         * @author chentailai
         * @description 根据传进来的 运营范围 模糊匹配值，直到匹配到之后返回对应的key，匹配不到则返回 其他
         * @date 2021/1/15 2:50 下午
         * @params [originVal]
         */
        public static VehicleTransType getKeyByValLike(String originVal) {
            VehicleTransType[] list = VehicleTransType.values();
            for (VehicleTransType one : list) {
                if (originVal.contains(one.transTypeKey)) {
                    return one;
                }
            }
            return VehicleTransType.OTHER;
        }

        /**
         * @return com.hd.common.constant.BizConstant.VehicleTransType
         * @author chentailai
         * @description 根据 运输范围名称 反向生成运输类型
         * @date 2021/3/6 10:26 上午
         * @params [originVal]
         */
        public static VehicleTransType getTransTypeKeyByRule(String originVal) {

            //包含包车 但 不包含班车  识别为: 旅游客运
            if (originVal.contains("包车") && !originVal.contains("班车")) return TRAVEL;

            //包含班车且不包含危险 识别为: 班线客运
            if (originVal.contains("班车") && !originVal.contains("危险")) return PASSENGER;

            //包含 危险 识别为危险品
            if (originVal.contains("危险")) return DANGER;

            //包含 普通货物 但不包含危险 识别为 普通货物运输
            if (originVal.contains("普通货物") && !originVal.contains("危险")) return FREIGHT;


            return VehicleTransType.OTHER;
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum VehicleNoColor {
        BLUE("1", "蓝色"),
        YELLOW("2", "黄色"),
        BLACK("3", "黑色"),
        WHITE("4", "白色"),
        GREEN("5", "绿色"),
        N_BLUE("6", "农蓝"),
        N_YELLOW("91", "农黄"),
        N_GREEN("92", "农绿"),
        GRADUAL_GREEN1("93", "黄绿色"),
        GRADUAL_GREEN2("94", "渐变绿色"),
        YELLOW_GREEN("97", "黄绿双拼"),
        OTHER("9", "其他"),
        UN_KNOWN("unKnown", "未知");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static VehicleNoColor get(String key) {
            if (StringUtils.isBlank(key)) return VehicleNoColor.OTHER;
            VehicleNoColor[] list = VehicleNoColor.values();
            for (VehicleNoColor one : list) {
                if (one.key.equals(key)) {
                    return one;
                }
            }
            return VehicleNoColor.OTHER;
        }

        /**
         * @return com.hd.common.constant.BizConstant.VehicleNoColor
         * @author chentailai
         * @description 有 val 取值
         * @date 2021/1/14 8:50 上午
         * @params [key]
         */
        public static VehicleNoColor getByVal(String val) {
            if (StringUtils.isBlank(val)) return VehicleNoColor.UN_KNOWN;
            VehicleNoColor[] list = VehicleNoColor.values();
            for (VehicleNoColor one : list) {
                if (one.val.equals(val)) {
                    return one;
                }
            }
            return VehicleNoColor.UN_KNOWN;
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum StaticDataStatus {
        SYNC_NOT_YET(0, "未同步"),
        SYNC_COMPLETED(1, "同步成功"),
        SYNC_FAILED(2, "同步异常");

        private Integer key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(Integer key) {
            if (key == null) return "";
            StaticDataStatus[] list = StaticDataStatus.values();
            for (StaticDataStatus one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

    }

    @Accessors(fluent = true)
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum Specification {
        JIAN("1", "件"),
        GE("2", "个");

        private String key;
        private String val;


        /**
         * @return java.lang.String
         * @Author whdsj
         * @Description 由 key 取值
         * @Name get
         * @Create 15:22 2020/12/1 0001
         * @Param [key]
         **/
        public static String get(String key) {
            if (StringUtils.isBlank(key)) return "";
            Specification[] list = Specification.values();
            for (Specification one : list) {
                if (one.key.equals(key)) {
                    return one.val;
                }
            }
            return "";
        }

        /*
         * @Author chentl
         * @Description 根据val 获取 key
         * @Date 21:37 2022/4/22
         * @Param [val]
         * @Return java.lang.String
         **/
        public static String reverse(String val) {
            if (StringUtils.isBlank(val)) return "";
            Specification[] list = Specification.values();
            for (Specification one : list) {
                if (one.val.equals(val)) {
                    return one.key;
                }
            }
            return "";
        }
    }
}
